//
//  leadPageViewController.m
//  one_mile_01
//
//  Created by 王进帅 on 15/10/27.
//  Copyright © 2015年 王雅蓉. All rights reserved.
//

#import "leadPageViewController.h"

@interface leadPageViewController ()

@end

@implementation leadPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor yellowColor];
    self.scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.scrollView.delegate = self;
    self.scrollView.backgroundColor = [UIColor yellowColor];
    self.scrollView.contentSize = CGSizeMake([[UIScreen mainScreen]bounds].size.width * 3, 0);
    [self.view addSubview:self.scrollView];
    
    for (int i = 0; i < 3; i++) {
        
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake([[UIScreen mainScreen]bounds].size.width * i, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];
        NSString *name = [NSString stringWithFormat:@"images0%d@2x", i + 1];
        NSString *filePath = [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
        self.imageView.image = [UIImage imageWithContentsOfFile:filePath];
        [self.scrollView addSubview:self.imageView];
    }
    
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    
    //self.pageC = [[UIPageControl alloc] init];
    self.pageC.backgroundColor = [UIColor clearColor];
    self.pageC.numberOfPages = 3;
    self.pageC.currentPage = 0;
    self.pageC.tag = 10001;
    self.pageC.currentPageIndicatorTintColor = [UIColor whiteColor];
    self.pageC.pageIndicatorTintColor = [UIColor lightGrayColor];
    
    [self.pageC addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    //[self.view addSubview:self.pageC];
    
    
    [self.pageC mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_bottom).offset(-130);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.offset(150);
        make.height.offset(40);
    }];
}

-(void)pageAction:(UIPageControl *)page
{
    
    [self.scrollView setContentOffset:CGPointMake([[UIScreen mainScreen]bounds].size.width * page.currentPage, 0) animated:YES];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    
    UIPageControl *tmp = (UIPageControl *)[self.view viewWithTag:10001];
    tmp.currentPage = scrollView.contentOffset.x/[[UIScreen mainScreen]bounds].size.width;
    if (self.scrollView.contentOffset.x / [[UIScreen mainScreen]bounds].size.width == 2 ) {
        UIButton *button = [[UIButton alloc]init];
        [button setTintColor:[UIColor whiteColor]];;
        [button setTitle:@"点击体验" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:17 * FITRATE];
        button.backgroundColor = [UIColor clearColor];
        button.layer.cornerRadius = 6 * FITRATE;
        [button.layer setBorderWidth:2 * FITRATE];
        [button.layer setBorderColor:[[UIColor whiteColor] CGColor]];
        [self.view addSubview:button];
        
        
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view.mas_bottom).offset(-70 * FITRATE);
            make.centerX.equalTo(self.view.mas_centerX);
            make.width.offset(150 * FITRATE);
            make.height.offset(40 * FITRATE);
        }];
        
        [button addTarget:self  action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    }
}


-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return [scrollView.subviews objectAtIndex:0];
}

-(void)buttonAction{
    
    [self.myDelegate change];
    
}

-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
